package cn.tedu.user.management.dao.persist.repository.impl;

import cn.tedu.user.management.dao.persist.mapper.RoleMapper;
import cn.tedu.user.management.dao.persist.mapper.UserRoleMapper;
import cn.tedu.user.management.dao.persist.repository.IRoleRepository;
import cn.tedu.user.management.pojo.entity.UserRole;
import cn.tedu.user.management.pojo.vo.RoleListItemVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class RoleRepositoryImpl implements IRoleRepository {

    @Autowired
    RoleMapper roleMapper;
    @Autowired
    UserRoleMapper userRoleMapper;

    @Override
    public List<RoleListItemVO> roleList() {
        log.debug("开始执行【根据查询职位列表】的操作");
        return roleMapper.roleList();
    }

    @Override
    public int countByUserId(Long id) {
        log.debug("开始执行【查询目标员工角色数量】的操作");
        QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",id);
        return userRoleMapper.selectCount(queryWrapper);
    }
}
